#define _CRT_SECURE_NO_WARNINGS 1

#include"Stack.h"

void s::StackInit(Stack* ps, int n)
{
	ps->a = (int*)malloc(sizeof(int) * n);
	if (ps->a == NULL)
	{
		perror("malloc fail");
		return;
	}
	ps->top = 0;
	ps->capacity = n;
}

void s::StackPush(Stack* ps, int x)
{
	if (ps->top == ps->capacity)
	{
		int* ptr = (int*)realloc(ps->a, sizeof(int) * ps->capacity * 2);
		if (ptr == NULL)
		{
			perror("realloc fail");
			return;
		}
		ps->capacity *= 2;
	}
	ps->a[ps->top] = x;
	ps->top++;
}